<template>
  <view class="content">
    <u-sticky
      style="height: 110upx;"
      bg-color="#F8F9FC">
      <view
        class="topsearch x-row fff">
        <view
          class="x-col-center x-col">
          <view
            class="search">
            <u-search
              placeholder="请输入搜索客户名称"
              @change="changeSearch"
              shape="square"
              bg-color="#fff"
              :show-action="false"
              height="70"
              v-model="keywords">
            </u-search>
          </view>
        </view>
      </view>
    </u-sticky>

    <order-list :list="clist">
    </order-list>
    <u-empty text="暂无数据"
      mode="list"
      v-if="!clist.length">
    </u-empty>
  </view>
</template>

<script>
import orderList from '@/components/order-list'
export default {
  components: { orderList },
  data() {
    return {
      show: false,
      keyword: '',
      img: this.urlimg + 'mini/',
      list: [
        {
          text: '客户资料'
        },
        {
          text: '商家总数据'
        },
        {
          text: '商家订单'
        }
      ],
      keywords: '',
      clist: [],
      isAllList: 1,
      page: 1,
      status: 'loading',
      loading: true,

      li: ''
    }
  },
  onLoad(e) {
    uni.setNavigationBarTitle({
      title: '我的客户'
    })
    this.getList()
  },
  onReachBottom() {
    if (this.isAllList != 0) {
      this.getList()
    }
  },
  methods: {
    changeSearch() {
      var that = this
      this.defaultData(function () {
        that.getList()
      })
    },
    cellPhone(e) {
      uni.makePhoneCall({
        phoneNumber: e.phone
      })
    },
    toStore(e) {
      uni.openLocation({
        //​使用微信内置地图查看位置。
        latitude: parseFloat(e.lat), //要去的纬度-地址
        longitude: parseFloat(e.lon), //要去的经度-地址
        name: e.map_address
      })
    },
    gotoPage(url) {
      this.$api.navigator(url)
    },
    clickMsg(e) {
      this.li = e
      this.show = true
    },
    onSheet(e) {
      switch (e) {
        case 0:
          uni.navigateTo({
            url: 'my_customer_detail?id=' + this.li.id
          })
          break
        case 1:
          uni.navigateTo({
            url: 'my_customer_total?id=' + this.li.id
          })
          break
        case 2:
          uni.navigateTo({
            url: '../sale/order_customer?id=' + this.li.id
          })
          break
      }
    },
    defaultData(callback) {
      this.isAllList = 1
      this.page = 1
      this.clist = []
      this.status = 'loading'
      this.loading = true
      if (callback) {
        callback()
      }
    },
    getList() {
      let that = this,
        params = {
          keywords: this.keywords,
          page: this.page,
          limit: getApp().globalData.limit
        }
      this.$axios('api/MrkBasic/ListPaged', 'post', { value: 0 }).then(res => {
        that.loading = false
        if (res.result.length == 0) {
          that.isAllList = 0
          that.status = 'nomore'
        } else {
          var list = that.clist
          res.result.map(e => {
            list.push(e)
          })
          that.clist = list
          that.page = that.page + 1
          if (that.clist.length < 20 && that.page == 2) that.getList()
        }
      })
    }
  }
}
</script>
